<?php namespace system\model;
use houdunwang\model\Model;
class Tag extends Model{
	//数据表
	protected $table = "tag";
	//添加
    public function store(){
       //验证
		if (strlen($_POST['tname'])==0){
		   return ['valid'=>0,'message'=>'请填写标签内容'];
		}
		//接收数据拆成数组
	   $tags=explode('|',$_POST['tname']);
//		p($tags);
	   foreach ($tags as $k=>$v){
	      $this->insertGetId(['tname'=>$v]);
	   }
	   return ['valid'=>1,'message'=>'添加成功'];
	}
	//编辑
   public function edit($tid){
	  //验证
	  if (strlen($_POST['tname'])==0){
		 return ['valid'=>0,'message'=>'请填写标签内容'];
	  }
	  $this->where('tid',$tid)->update(['tname'=>$_POST['tname']]);
	  return ['valid'=>1,'message'=>'编辑成功'];
   }
}